﻿using System.Web.Mvc;
using System.Web.Routing;
using Framework.Poco;
using Framework.Mvc;

namespace MyMvcApplication
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    /// <summary>
    /// MVC应用程序
    /// </summary>
    public class MvcApplication : System.Web.HttpApplication
    {
        /// <summary>
        /// 注册全局过滤器
        /// </summary>
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        /// <summary>
        /// 路由注册
        /// </summary>
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{currentPage}/{pageSize}", // 带有参数的 URL
                new { controller = "Home", action = "Index", currentPage = 1, pageSize = 20 } // 参数默认值
            );

            routes.MapRoute(
                "Default2", // 路由名称
                "{controller}/{action}", // 带有参数的 URL
                new { controller = "Home", action = "Index" } // 参数默认值
            );
        }

        /// <summary>
        /// 应用程序启动时所创建的信息
        /// </summary>
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            ModelBinders.Binders.Add(typeof(Agency), new AgencyModelBinder());
            ModelBinders.Binders.Add(typeof(User), new UserModelBinder());
            ModelBinders.Binders.Add(typeof(FilesUploaded), new FilesUploadedModelBinder());
            EntityRegister.Register();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}